package com.learn.mq.listener;

import com.alibaba.fastjson2.JSON;
import com.learn.mq.beans.Person;
import com.learn.mq.param.Message;
import com.learn.mq.param.MessageBody;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * ClassName:MsgListener
 * Package:com.learn.mq.listener
 * Description:
 *
 * @Author:@郭先森
 * @Create:2025/7/30 - 18:45
 * @Version:v1.0
 */
@Slf4j
@Component
@RocketMQMessageListener(topic = "GXC-ROCKETMQ-STARTER",consumerGroup = "MSG-CONSUMER-1",selectorExpression = "GXS")
public class MsgListener implements RocketMQListener<Message> {
    @Override
    public void onMessage(Message message) {
        log.info("收到的原始的消息："+message);
        MessageBody body = JSON.parseObject(message.getBody(), MessageBody.class);
        log.info("获得了body，body的幂等号为"+body.getIdentifier());
        Person person = JSON.parseObject(body.getBody(), Person.class);
        log.info("解析出来了person: "+person);
        log.info("业务处理中.......");
        log.info("业务处理完成.......");
    }
}
